/*
 * @Author       : 乐乐侠在此
 * @Date         : 2024-02-19 16:13:07
 * @LastEditors  : Please set LastEditors
 * @LastEditTime : 2024-02-20 09:23:28
 * @Description  : 懒汉模式
 */
#include <iostream>
using namespace std;

class Singleton
{
private:
    /* data */
    int data;
    Singleton() : data(0){};

public:
    // 删除拷贝构造函数和拷贝赋值操作符，确保单例不被拷贝
    Singleton(const Singleton &) = delete;
    Singleton &operator=(const Singleton &) = delete;
    int showData()
    {
        std::cout << "my data is:" << data << std::endl;
        return 0;
    }

    int setData(int val)
    {
        data = val;
        return 0;
    }
    static Singleton &getInstance()
    {
        static Singleton instance;
        return instance;
    }
};

int main()
{
    Singleton::getInstance().setData(2);
    Singleton::getInstance().showData();
}